<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<!--{include file='comm/header.tpl'}-->
    <title>发布管理</title>
</head>
<body>

<div class="container">

    <div class="comm_crub">
        <span class="now_crub">发布管理</span>
    </div>

    <div class="comm_content">

            <div class="search-box">
                <div style="position:relative">
                    <form id="searchForm">
                        <table>
                            <tr>
                                <td>
                                    <span>当前用户名：<font id="issueUsername" name="issueUsername"><!--{$issueUsername}--></font></span>
                                    <span>
                                        版本号：
                                        <select id="versionNumber" name="versionNumber" style="width:100px;">
                                            <option value="">请选择</option>
                                            <!--{if $versionNumberInfo}-->
                                            <!--{foreach from=$versionNumberInfo item=value}-->
                                            <option value="<!--{$value}-->"><!--{$value}--></option>
                                            <!--{/foreach}-->
                                            <!--{/if}-->
                                        </select>
                                    </span>
                                    <span><input type="button" class="btn" value="发布" id="searchBtn" name="searchBtn" onclick="source.issue();"></span>
                                    <span id='error_msg' style="display:none;"><!--{$error_msg}--></span>
                                    <span>
                                        选择筛选类型：
                                        <select id="issueType" name="issueType" onchange="source.search();">
                                            <option value="">请选择</option>
                                            <option value="1">测试服务器未确认</option>
                                            <option value="2">测试服务器已确认</option>
                                            <option value="3">正式服务器未发布</option>
                                            <option value="4">正式服务器已发布</option>
                                            <option value="5">正式服务器已回滚</option>
                                        </select>
                                    </span>
									<span><input type="button" class="btn btn-primary" value="刷新" onclick="location.reload();"></span>
                                </td>
                            </tr>
                        </table>
                    </form>
                </div>
            </div>

            <table id="flex" style="display:none"></table>

        </div>

</div>
	
	<script>
		
		$(document).ready(function(){
			var error_msg = $('#error_msg').html();
			if(error_msg != ''){
				E.alert(error_msg);
			}
		});
		
		$("#flex").flexigrid({
			url:"/invokingAjax-backend/project/issueInfo.ajax?operFlg=1",
	        dataType: "json",
	        colModel : [
				{display: "发布号", name : "issueID" , width : 80 , sortable : false },
	            {display: "发布人", width : 100},
	            {display: "版本号", width : 80},
	            {display: "发布时间", width : 140},
	            {display: "确认发布[测试服务器]", width : 140, align: 'center'},
	            {display: "是否回滚[测试服务器]", width : 140, align: 'center'},
	            {display: "发布结果", width : 80, align: 'center'},
				{display: "操作[正式服务器]", width : 140, align: 'center'}
	        ],
			sortname: "issueID",
	        sortorder: "desc",
	        usepager: true,
	        rp: 10,
	        useRp: true,
	        showTableToggleBtn: true,
			width: 900,
			height:400
		});
		
		var source = {
			
			//显示版本号对应的文件
			issue : function(){
				var versionNumber = $('#versionNumber').val();
				if(versionNumber == ''){
					E.alert('请选择发布号');
				}else{
					$.ajax({
						type: "POST",
						url:  "/invokingAjax-backend/project/issueInfo.ajax?operFlg=4",
						data: {'versionNumber' : versionNumber},
						dataType: "JSON",
						success: function( result_obj ) {
                        	if (result_obj.code == 200) {
								var dataParam = result_obj.message;
//	                            $("#flex").flexReload();
	                            var htmlCode = '';
								for (var i=0;i<dataParam.length;i++){
									htmlCode += dataParam[i]+'<br/>';
								}
								source.pre_deploy();
//								E.confirm(htmlCode,'source.pre_deploy()');
	                        } else {
	                            E.alert(result_obj.message);
	                        }
	                    }
					});
				}
			},
			
			pre_deploy: function(){
				var versionNumber = $('#versionNumber').val();
				if(versionNumber == ''){
					E.alert('请选择发布号');
				}else{
					E.open("/quanliadmin/app/project/issueInfo.pscript?operFlg=4&versionNumber=" + versionNumber);
				}
			},
			
			//查询
			search: function() {
	            var dt = $('#searchForm').serializeArray();
//				var dt = {'issueUsername' : $('#issueUsername').text() , 'issueType' : $('#issueType').val()};
	            $("#flex").flexOptions({params: dt}).flexReload();
	        },
			
			
			
			//刷新页面
			load: function() {
				
	            $("#flex").flexReload();
	        },
			
						
		}
		
		//发布按钮事件
		$('#searchBtn').click(function(issueID, versionNumber, flg){
			
		});
		
		var globFlg = '';
		var globVersionNumber = '';
		var globIssueID = '';
		
		//确认
		function check(issueID, versionNumber, flg){
			var msg = '';
				
				switch (flg) {
					case 1:
						msg = '确认在测试服上发布该版本吗？';
						break;
					case 2:
						msg = '确认在测试服上回滚该版本吗？';
						break;
					case 3:
						msg = '确认在正式服上发布该版本吗？';
						break;
					case 4:
						msg = '确认在正式服上回滚该版本吗？';
						break;
					default:
						E.alert('传值错误');
						break;
				}
				globFlg = flg;
				globVersionNumber = versionNumber;
				globIssueID = issueID;
				E.confirm(msg, 'doChange', 'noChange');
		}
		//发布、回滚等
		function doChange(){
			$.ajax({
					type: "POST",
					url:  "/invokingAjax-backend/project/issueInfo.ajax?operFlg=2",
					data: {'issueID':globIssueID, 'versionNumber':globVersionNumber, 'flg':globFlg},
					dataType: "JSON",
					success: function( result_obj ) {
                        if (result_obj.code == 200) {
                            $("#flex").flexReload();
                            E.alert(result_obj.message,  2);
                        } else {
                            E.alert(result_obj.message);
                        }
						globFlg = '';
						globVersionNumber = '';
						globIssueID = '';
						
                    }
				});
		}
		
		function noChange(){
			globFlg = '';
			globVersionNumber = '';
			globIssueID = '';
		}
		
		function showDetail(issueID, versionNumber){
			
			E.open("/quanliadmin/app/project/issueInfo.pscript?operFlg=5&versionNumber=" + versionNumber + "&issueID="+issueID);
			
		}
	</script>
</body>
</html>